package com.example.dqnm.service.impl;

import com.example.dqnm.mapper.ShippingaddressDao;
import com.example.dqnm.pojo.Shippingaddress;
import com.example.dqnm.pojo.ShippingaddressExample;
import com.example.dqnm.pojo.UserAddress;
import com.example.dqnm.service.ShippingaddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShippingaddressServiceImpl implements ShippingaddressService {
    @Autowired
    private ShippingaddressDao shippingaddressDao;
    @Override
    public List<Shippingaddress> selectAllShippingaddress(Integer id) {
        ShippingaddressExample shippingaddressExample = new ShippingaddressExample();
        ShippingaddressExample.Criteria criteria = shippingaddressExample.createCriteria();
        criteria.andUseridEqualTo(id);
        List<Shippingaddress> shippingaddresses = shippingaddressDao.selectByExample(shippingaddressExample);
        return shippingaddresses;
    }

    @Override
    public Boolean addUserAddress(Shippingaddress shippingaddress) {
        int i = shippingaddressDao.insertSelective(shippingaddress);
        return i > 0;
    }

    @Override
    public Boolean deleteUserAddress(Integer id) {
        int i = shippingaddressDao.deleteByPrimaryKey(id);
        return i > 0;
    }

    @Override
    public Boolean updateUserAddress(Shippingaddress shippingaddress) {
        int i = shippingaddressDao.updateByPrimaryKeySelective(shippingaddress);
        return i > 0;
    }
}
